package com.heaven.jane.sourcegenerator.business.project.service;

import java.util.Optional;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.heaven.jane.sourcegenerator.business.project.dao.ProjectRepository;
import com.heaven.jane.sourcegenerator.business.project.dao.ProjectSpec;
import com.heaven.jane.sourcegenerator.business.project.domain.Project;
import com.heaven.jane.sourcegenerator.business.project.domain.ProjectVo;

/**
 * 用户业务类
 * @author heaven
 *
 */
@Service
public class ProjectServiceImpl implements ProjectService{
	
	@Autowired
	private ProjectRepository projectRepository;
	
	@Override
	public Page<Project> list(Optional<ProjectVo> condition, Pageable pageable) {
		Page<Project> projects = projectRepository.findAll(ProjectSpec.builder().condition(condition).build(), pageable);
		return projects;
	}

	@Override
	public Project save(ProjectVo data) {
		Project target = new Project();
		BeanUtils.copyProperties(data, target);
		projectRepository.save(target);
		return target;
	}

	@Override
	public void delete(ProjectVo data) {
		Project target = new Project();
		BeanUtils.copyProperties(data, target);
		projectRepository.delete(target);
	}
}
